package org.example.wratablecomparable;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @ClassName FlowMapper
 * @Author 小坏
 * @Date 2021/7/16、17:10
 * @Version 1.0
 * <p>
 * 1、输入的 K,V
 * LongWritable, Text(一行)
 * <p>
 * 1、输出的 K,V
 * Text(手机号), FlowBean(FlowBean对象)
 */
public class FlowMapper extends Mapper<LongWritable, Text, FlowBean, Text> {

    private FlowBean outV = new FlowBean();
    private Text outK = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //获取一行
        String line = value.toString();
        //切割
        String[] split = line.split("\t");

        outK.set(split[0]);
        outV.setUpFlow(Long.parseLong(split[1]));
        outV.setDownFlow(Long.parseLong(split[2]));
        outV.setSumFlow();

        //4 写出 outK outV
        context.write(outV,outK);
    }


}
